package com.zhuoyue.system.service.impl;

import java.util.List;

import com.zhuoyue.common.annotation.DataScope;
import com.zhuoyue.system.domain.po.TblHomePo;
import com.zhuoyue.system.domain.vo.TblHomePositionVo;
import com.zhuoyue.system.domain.vo.TblHomeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zhuoyue.system.mapper.TblHomeMapper;
import com.zhuoyue.system.service.ITblHomeService;

/**
 * 家庭Service业务层处理
 *
 * @author hewenze
 * @date 2020-08-07
 */
@Service
public class TblHomeServiceImpl implements ITblHomeService {
    @Autowired
    private TblHomeMapper tblHomeMapper;


    /**
     * 查询家庭列表
     *
     * @param tblHomePo 家庭
     * @return 家庭
     */
    @Override
    @DataScope(deptAlias = "s_d")
    public List<TblHomeVo> selectTblHomeList(TblHomePo tblHomePo) {
        return tblHomeMapper.selectTblHomeList(tblHomePo);
    }

    @Override
    @DataScope(deptAlias = "s_d")
    public List<TblHomePositionVo> selectTblHomePositionList(TblHomePo tblHomePo) {
        List<TblHomePositionVo> tblHomePositionVos = tblHomeMapper.selectTblHomePositionList(tblHomePo);
//        Map<String, List<TblHomePositionVo>> collect = tblHomePositionVos.stream().collect(Collectors.groupingBy(TblHomePositionVo::getUserId));
//        List<TblHomePositionVo> resultList = new ArrayList<>(10);
//        for (Map.Entry<String, List<TblHomePositionVo>> entry : collect.entrySet()) {
//            if (entry.getValue().size() == 1) {
//                resultList.add(entry.getValue().get(0));
//            } else {
//                TblHomePositionVo tblHomePositionVo = new TblHomePositionVo();
//                TblHomePositionVo firstHome = entry.getValue().get(0);
//                tblHomePositionVo.setUserId(firstHome.getUserId());
//                tblHomePositionVo.setHomeId(firstHome.getHomeId() + "-" + entry.getValue().size());
//                tblHomePositionVo.setAccount(firstHome.getAccount());
//                tblHomePositionVo.setNickName(firstHome.getNickName());
//                tblHomePositionVo.setChildrenHome(entry.getValue());
//                resultList.add(tblHomePositionVo);
//            }
//        }
        return tblHomePositionVos;
    }

    @Override
    @DataScope(deptAlias = "s_d")
    public Integer getHomeCount(TblHomePo tblHomePo) {
        return tblHomeMapper.getHomeCount(tblHomePo);
    }
}
